<?php
class IndexController extends Controller
{
	public function listAction()
	{
		$pageno = isset($_GET['pageno']) ? (int) $_GET['pageno'] : 1; // 当前页
		if ($pageno <= 0) 
			$pageno = 1;
		
		$perPageResults = 5; //每页显示条数
		$totalResults = V::getAdapter()->table('users')->fields('user_id', '', 'COUNT')->where(array('user_status = ?', 'y'))->getColumnOne();
		$pagelist = Pagelist::getInstance($pageno, $totalResults, $perPageResults);
		
		$this->view->users = V::getAdapter()->table('users')->where(array('user_status = ?', 'y'))
		->limit($pagelist->_startResult, $pagelist->_perPageResults)->select();
		$this->view->show = $pagelist->display('page.php?s=index/list&pageno=', Pagelist::URL_A);
	}
	
	/**
	 * 向vo_users表插入100条记录
	 */
	public function addAction()
	{	
		for ($i=0; $i<100; $i++)
		{
			$email = '';
			switch(mt_rand(0, 3))
			{
				case 0 : $email = '@sina.com';
					break;
				case 1 : $email = '@163.com';
					break;
				case 2 : $email = '@126.com';
					break;
				case 3 : $email = '@qq.com';
					break;
			}
			
			$user = array(
				'user_loginname' => Helper::randStr(mt_rand(6, 10), 'LETTER') . '_' . $i,
				'user_password' => md5(Helper::randStr(9)),
				'group_id' => mt_rand(1, 5),
				'user_nicename' => Helper::randStr(mt_rand(6, 10), 'LETTER') . '_' . $i,
				'user_email' => Helper::randStr(mt_rand(6, 10), 'LETTER') . '_' . $i . $email,
				'dt_registered' => date('Y-m-d H:i:s', mktime() - mt_rand(0, 3600*24*30*6)),
				'ip_last_login' => mt_rand(1, 255) . '.' . mt_rand(1, 255) . '.' . mt_rand(1, 255) . '.' . mt_rand(1, 255),
				'dt_last_login' => date('Y-m-d H:i:s', mktime() - mt_rand(0, 3600*24*30*6)),
				'user_status' => mt_rand(0, 1) === 0 ? 'n' : 'y',
			);
			
			V::getAdapter()->table('users')->fields($user)->insert();
			echo V::getAdapter()->getSql(), '<br/>';
		}
		exit;
	}
	
	
} 
